package cn.richinfo.sparkdemo;

import java.util.ArrayList;
import java.util.List;

public class MyList {
	private List<String> list;
	public MyList( List<String> list){
		this.list=list;
	}
	
	public List<String> getMyList() {
		return list;
	}
	public void foreach(){
		System.out.println("正在遍历list。。。");
		for(String s:list){
			System.out.println(s);
		}
	}
 

	public MyList map(Operator o){
		List<String> newList=new ArrayList();
		for(String line:list){
			String result=o.operate(line);
			newList.add(result);
		}
		return new MyList(newList);
	}
	
	public static void main(String[] args) {
		List<String> initList=new ArrayList(); 
		initList.add("a");
		initList.add("b");
		initList.add("c");
		initList.add("d");
		MyList myList=new MyList(initList);
		MyList mynewlist=myList.map(new Operator() {
			
			public String operate(String line) {
				// TODO Auto-generated method stub
				return line.toUpperCase();
			}
		});
		
		mynewlist.foreach();
		
		MyList mynewlist2=myList.map(new Operator() {
			
			public String operate(String line) {
				// TODO Auto-generated method stub
				return "to_"+line;
			}
		});
		
		mynewlist2.foreach();
		
	}
}

interface Operator{
	String operate(String line);
}
